package com.erbao.interview;

/**
 * 两个线程打印：A1B2C3D4E5F6G7H8I9J10K11L12M13N14O15P16Q17R18S19T20U21V22W23X24Y25Z26
 * cas玩法
 * @author CaoBaoYin
 * @since 2022/2/27 20:55
 */
public class AlternatelyPrintCas {
    static Thread t1, t2;
    enum T {
        t1, t2;
    }
    static volatile T t = T.t1;

    public static void main(String[] args) {
        t1 = new Thread(() -> {
            for (int i = 0; i < 26; i++) {
                while (!t.equals(T.t1)) {}
                System.out.print((char)('A' + i));
                t = T.t2;
            }
        });
        t2 = new Thread(() -> {
            for (int i = 0; i < 26; i++) {
                while (!t.equals(T.t2)) {}
                System.out.print(1 + i);
                t = T.t1;
            }
        });

        t2.start();
        t1.start();
    }


}
